package data;

import java.io.File;
import java.util.Date;

public class Woche {
	
	private Tag[] tage;
	private int wochenNummer;
	private File relatedFile;
	
	private boolean edited = false;
	
	public Woche() {
		tage = new Tag[5];
		for(int i = 0; i < 5; i++) {
			tage[i] = new Tag();
		}
	}
	
	public Tag getTag(int index) {
		return tage[index];
	}
	
	public void setWochenNummer(int nummer) {
		wochenNummer = nummer;
	}
	
	public int getWochenNummer() {
		return wochenNummer;
	}
	
	public String getStartDatumString() {
		return tage[0].getDatumString();
	}
	
	public Date getStartDatum() {
		return tage[0].getDatum();
	}
	
	public String getEndDatumString() {
		return tage[tage.length-1].getDatumString();
	}
	
	public Date getEndDatum() {
		return tage[tage.length-1].getDatum();
	}
	
	public String getGesamtZeit() {
		float ges = 0;
		
		for (int i = 0; i < tage.length; i++) {
			ges += tage[i].getZeitAsFloat();
		}
		
		if(ges == 0f) {
			return "";
		}
		
		String str = ("" + ges).replace(".", ",");
		
		if(str.length() > 4) {
			str = str.substring(0, 4);
		}
		
		if(str.endsWith(",0")) {
			str = str.substring(0, str.length()-2);
		}
		
		return str;
	}
	
	public void setRelatedFile(File relatedFile) {
		this.relatedFile = relatedFile;
	}
	
	public File getRelatedFile() {
		return relatedFile;
	}
	
	public void setEditedFlag(boolean edited) {
		this.edited = edited;
	}
	
	public boolean getEditedFlag() {
		return edited;
	}
	
	public boolean isEmpty() {
		int emptycount = 0;
		for(int i = 0; i < tage.length; i++) {
			if(tage[i].isEmpty()) {
				emptycount++;
			}
		}
		return (emptycount == tage.length);
	}
	
	public boolean isUnfinished() {
		for(int i = 0; i < tage.length; i++) {
			if(tage[i].isUnfinished()) {
				return true;
			}
		}
		return false;
	}
	
	@Override
	public String toString() {
		return wochenNummer + ". " + getStartDatumString() + " - " + getEndDatumString();
	}
	
	public String getFullDescriptorString() {
		return Lang.WEEK_FULL_DESC.replace("%NR", ""+getWochenNummer()).replace("%STARTDAT", getStartDatumString()).replace("%ENDDAT", getEndDatumString()).replace("%HOURS", "".equals(getGesamtZeit())?"0":getGesamtZeit());
	}
	
}
